﻿using System.Collections.Generic;

namespace AddressBook.Models
{
    public class PersonRepository
    {
        private readonly List<Person> _persons;

        public PersonRepository()
        {
            _persons = new List<Person>
                           {
                               new Person
                                   {
                                       Id = 1,
                                       FirstName = "Rahul",
                                       LastName = "Mehatha",
                                       City = "Bangalore",
                                       State = "Karntaka",
                                       Country = "India",
                                       PinCode = 45881
                                   }
                               ,
                               new Person
                                   {
                                       Id = 2,
                                       FirstName = "Eva",
                                       LastName = "Hemaelton",
                                       City = "California",
                                       State = "CA",
                                       Country = "United States",
                                       PinCode = 45881
                                   }
                               ,
                               new Person
                                   {
                                       Id = 3,
                                       FirstName = "Rahul",
                                       LastName = "Meru",
                                       City = "Bangalore",
                                       State = "Karntaka",
                                       Country = "India",
                                       PinCode = 45881
                                   }
                               ,
                               new Person
                                   {
                                       Id = 4,
                                       FirstName = "Ajantha",
                                       LastName = "Mendis",
                                       City = "Oslo",
                                       State = "Oslo",
                                       Country = "Norway",
                                       PinCode = 45881
                                   }
                               ,
                               new Person
                                   {
                                       Id = 5,
                                       FirstName = "Arun",
                                       LastName = "Kumar",
                                       City = "Bangalore",
                                       State = "Karntaka",
                                       Country = "India",
                                       PinCode = 34444
                                   }
                               ,
                               new Person
                                   {
                                       Id = 6,
                                       FirstName = "Ray",
                                       LastName = "Kalins",
                                       City = "California",
                                       State = "CA",
                                       Country = "United States",
                                       PinCode = 345345
                                   }
                           };
        }

        public IEnumerable<Person> FindAll()
        {
            return _persons;
        }

        public Person FindBy(int id)
        {
            return _persons.Find(p => p.Id == id);
        }

        public IList<Person> FindBy(string firstName, string lastName)
        {
            return _persons.FindAll(p => p.FirstName.StartsWith(firstName) || p.LastName.StartsWith(lastName));
        }
    }
}
